package com.spzx.cart.api.factory;

import com.spzx.cart.api.RemoteCartService;
import com.spzx.cart.api.domain.CartItem;
import com.spzx.common.core.domain.R;


import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class RemoteCartFallbackFactory implements FallbackFactory<RemoteCartService> {
    @Override
    public RemoteCartService create(Throwable cause) {
        log.error("购物车服务调用失败:{}", cause.getMessage());
        return new RemoteCartService() {
            @Override
            public R<List<CartItem>> getCheckedCartItems() {
                return R.fail("获取结算页购物项数据失败:" + cause.getMessage());
            }

            @Override
            public R<Boolean> delCheckedCartItems() {
                return R.fail("删除购物车中的购物项失败:" + cause.getMessage());
            }
            //            @Override
            //            public R<List<Brand>> listAllBrands() {
            //                return  R.fail("获取品牌数据失败:" + cause.getMessage());
            //            }
        };
    }
}